package mipo.top.pet.controller;

import mipo.top.base.util.JsonResult;
import mipo.top.base.util.PageUtil;
import mipo.top.pet.Service.IPetTypeService;
import mipo.top.pet.domain.PetType;
import mipo.top.pet.query.PetTypeQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/petType")
public class PetTypeController {

    @Autowired
    private IPetTypeService petTypeService;

    @GetMapping
    public List<PetType> sad(){
        return petTypeService.findall();
    }

    @PutMapping
    public JsonResult su(@RequestBody PetType petType){
        try {
            if(petType.getId()==null){
                petTypeService.save(petType);
            }else{
                petTypeService.update(petType);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("错误数据");
        }
    }

    @DeleteMapping("/{id}")
    public void adw(@PathVariable("id") Long id){
        petTypeService.remove(id);
    }

    @PostMapping
    public PageUtil<PetType> asp(@RequestBody PetTypeQuery petTypeQuery){
        return petTypeService.queryData(petTypeQuery);
    }
    @PatchMapping
    private void bacthDel(@RequestBody List<Long> ids){
        petTypeService.patchremove(ids);
    }

    @PostMapping("/Tree")
    private List<PetType> petTree(){
        return petTypeService.petTree();
    }
}
